##!/usr/bin/env python3
# -*- coding: utf-8 -*-

import base64


def safe_base64_decode(s):
    n = 4 - len(s) % 4
    for i in range(0, n):
        s = s + b'='
    return base64.b64decode(s)


# 测试:
assert b'abcd' == safe_base64_decode(b'YWJjZA=='), safe_base64_decode('YWJjZA==')
assert b'abcd' == safe_base64_decode(b'YWJjZA'), safe_base64_decode('YWJjZA')
print('ok')